package com.ruoyi.web.qualityController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.quality.QualityWarehouseWarrant;
import com.ruoyi.system.service.IQualityWarehouseWarrantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author GE-LV5
 * @create 2023/3/1 11:18
 * 入库单
 */
@Api(tags = "入库单的增删改查")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/quality/warehouse")
@Slf4j
public class QualityWarehouseWarrantController extends BaseController {

    @Autowired
    IQualityWarehouseWarrantService iQualityWarehouseWarrantService;


    /**
     * 入库单查询列表
     *
     * @param quality
     * @return
     */
    //@PreAuthorize("@ss.hasPermi('system:warehouse:list')")
    @ApiOperation(value = "查询入库单列表")
    @PostMapping("/list")
    public TableDataInfo list(QualityWarehouseWarrant quality) {
        startPage();
        List<QualityWarehouseWarrant> list = iQualityWarehouseWarrantService.selectTransferSlipList(quality);
        return getDataTable(list);
    }


    @ApiOperation("删除入库单")
    @DeleteMapping("delete/id")
    public AjaxResult deleteList(Long id) {
        iQualityWarehouseWarrantService.deleteEquipmentLedgerById(id);
        return AjaxResult.success("删除成功！");
    }


    /**
     * 新增入库单
     */
    //@PreAuthorize("@ss.hasPermi('stores:warehouse:add')")
    @Log(title = "问题反馈", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增入库单")
    @PostMapping("/add")
    public AjaxResult add(@ApiParam(value = "新增问题反馈实体类", required = true) @RequestBody QualityWarehouseWarrant OrdersManual) {
        return toAjax(iQualityWarehouseWarrantService.insertEquipmentLedger(OrdersManual));
    }

    /**
     * 修改入库单
     */
    //@PreAuthorize("@ss.hasPermi('stores:warehouse:update')")
    @Log(title = "修改入库单", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改入库单")
    @PutMapping("/update")
    public AjaxResult edit(@ApiParam(value = "问题反馈实体类", required = true) @RequestBody QualityWarehouseWarrant ordersManual) {

        return toAjax(iQualityWarehouseWarrantService.updateOrdersManual(ordersManual));
    }


    /**
     * 查询入库单详情
     */
    //@PreAuthorize("@ss.hasPermi('stores:warehouse:id')")
    @ApiOperation(value = "查询入库单详情")
    @GetMapping("/id")
    public QualityWarehouseWarrant warehouseById(Long id) {

        return iQualityWarehouseWarrantService.warehouseById(id);
    }

}
